package cn.edu.scau.cmi.dengzejun.chapter11;

import java.awt.*;
import java.awt.event.*;
import java.util.*;

import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;

import java.io.*;
import javax.swing.*;

public class PoliceListenForEight implements DocumentListener{
	JTextArea inputText,showText;
	public void setInputText(JTextArea input) {
		this.inputText = input;
		return;
	}
	
	public void setShowText(JTextArea show) {
		this.showText = show;
		return;
	}

	@Override
	public void changedUpdate(DocumentEvent arg0) {
		// TODO Auto-generated method stub
		String str = this.inputText.getText();
		String regex = "[\\s\\s\\p{pPunct}]+";
		String[] words = str.split(regex);
		Arrays.sort(words);
		this.showText.setText(null);
		for (String s:words) {
			this.showText.append(s+" ");
		}
	}

	@Override
	public void insertUpdate(DocumentEvent arg0) {
		// TODO Auto-generated method stub
		this.changedUpdate(arg0);
		return;
	}

	@Override
	public void removeUpdate(DocumentEvent arg0) {
		// TODO Auto-generated method stub
		this.changedUpdate(arg0);
		return;
	}

}
